package com.jiaai.web.xiaoke;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.exception.ServerException;
import com.jiaai.trade.api.TTradeApi;
import com.jiaai.trade.model.TCountTradeVO;
import com.jiaai.trade.model.TTradeAnchorIdVO;
import com.jiaai.trade.model.TTradeVO;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author 佳爱网络科技
 * @version V1.0
 * @title appTradeController
 * @since 2017/12/27
 */
@RestController
@RequestMapping("/api/v1/admin/trade")
public class TradeController {
    @Reference
    private TTradeApi tradeApi;
    /**
     * 获取所有申请中的公会列表
     * @param curr
     * @param tTradeVO
     * @return
     * @throws Exception
     */
    @GetMapping("/findAll")
    @ResponseBody
    public Object findAll(@RequestParam(defaultValue = "0", required = false) Integer curr, TTradeVO tTradeVO ) throws Exception {
        return RestResultGenerator.genSuccessResult(tradeApi.findAll(curr, tTradeVO));
    }
    /**
     * 获取所有公会列表
     * @param curr
     * @param tTradeVO
     * @return
     * @throws Exception
     */
    @GetMapping("/findByAll")
    @ResponseBody
    public Object findByAll(@RequestParam(defaultValue = "0", required = false) Integer curr, TTradeVO tTradeVO ) throws Exception {
        return RestResultGenerator.genSuccessResult(tradeApi.findByAll(curr, tTradeVO));
    }



    /**
     * 获取单个公会
     * @param tradeId
     * @return
     * @throws Exception
     */
    @PostMapping("/findById")
    public Object findById(Integer tradeId ) throws ServerException {
        try {
            return RestResultGenerator.genSuccessResult(tradeApi.findById(tradeId));
        } catch (Exception e) {
            throw new ServerException("查询失敗");
        }
    }
    /**
     * 删除单个公会
     * @param tradeId
     * @return
     * @throws Exception
     */
    @PostMapping("/delete")
    public Object delete(Integer tradeId ) throws ServerException {
        try {
            tradeApi.delete(tradeId);
            return RestResultGenerator.genSuccessResult("删除成功");
        } catch (Exception e) {
            throw new ServerException("删除失败");
        }
    }
    /**
     * 添加编辑公会
     * @param tTradeVO
     * @return
     * @throws Exception
     */
    @PostMapping("/edit")
    public Object edit(@RequestBody TTradeVO tTradeVO ) throws ServerException {
        try {
            tradeApi.update(tTradeVO);
            return RestResultGenerator.genSuccessResult("添加成功");
        } catch (Exception e) {
            throw new ServerException("添加失败");
        }
    }
    /**
     * 获取单个公会下面的所有成员
     * @param curr
     * @param tTradeVO
     * @return
     * @throws Exception
     */
    @GetMapping("/findByAllRole")
    @ResponseBody
    public Object findByAllRole(@RequestParam(defaultValue = "0", required = false) Integer curr, TTradeVO tTradeVO ) throws Exception {
        return RestResultGenerator.genSuccessResult(tradeApi.findByAllRole(curr, tTradeVO));
    }

    /**
     * 统计单个公会的所有主播和收益
     * @param curr
     * @param tCountTradeVO
     * @return
     * @throws Exception
     */
    @GetMapping("/countTrade")
    @ResponseBody
    public Object countTrade(@RequestParam(defaultValue = "0", required = false) Integer curr, TCountTradeVO tCountTradeVO ) throws Exception {
        return RestResultGenerator.genSuccessResult(tradeApi.countTrade(curr, tCountTradeVO));
    }
    /**
     * 获取单个公会下面的所有成员
     * @param curr
     * @param tTradeAnchorIdVO
     * @return
     * @throws Exception
     */
    @GetMapping("/findByAllAnchorId")
    @ResponseBody
    public Object findByAllAnchorId(@RequestParam(defaultValue = "0", required = false) Integer curr, TTradeAnchorIdVO tTradeAnchorIdVO ) throws Exception {
        return RestResultGenerator.genSuccessResult(tradeApi.findByAllAnchorId(curr, tTradeAnchorIdVO));
    }
    /**
     * 修改申请公会状态
     * @param tradeId
     * @param tradeState
     * @return
     * @throws Exception
     */
    @PostMapping("/changeState")
    @ResponseBody
    public Object changeState(Integer tradeId,Integer tradeState) throws ServerException {
        try {
            tradeApi.changeState(tradeId,tradeState);
            return RestResultGenerator.genSuccessResult("修改成功");
        } catch (Exception e) {
            throw new ServerException("修改失敗");
        }
    }

    /**
     * 修改公会比例
     * @param tradeId
     * @param commission
     * @return
     * @throws Exception
     */
    @PostMapping("/change")
    @ResponseBody
    public Object change(Integer tradeId,BigDecimal commission) throws ServerException {
        try {
            tradeApi.change(tradeId,commission);
            return RestResultGenerator.genSuccessResult("修改成功");
        } catch (Exception e) {
            throw new ServerException("修改失敗");
        }
    }


    /**
     * 统计单个家族所有成员
     * @param anchorId
     * @return
     * @throws Exception
     */
    @GetMapping("/count")
    public Object count(String anchorId ) throws ServerException {
        try {
            return RestResultGenerator.genSuccessResult(tradeApi.count(anchorId));
        } catch (Exception e) {
            throw new ServerException("查询失敗");
        }
    }
    /**
     * 查单个房间直播收益情况
     * @param liveId
     * @return
     * @throws Exception
     */
    @GetMapping("/giftMoney")
    public Object giftMoney(Integer liveId) throws ServerException {
        try {
            return RestResultGenerator.genSuccessResult(tradeApi.giftMoney(liveId));
        } catch (Exception e) {
            throw new ServerException("查询失敗");
        }
    }
}
